using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DacTaHinhThuc
{
    public partial class InsertParaFrm : Form
    {
        InputWizardFrm m_parent;
        
        public InsertParaFrm(InputWizardFrm parent)
        {
            InitializeComponent();
            this.m_parent = parent;
           
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            if (txtNamePara.Text.Length != 0 && comboType.Text.Length != 0)
            {
                Parameter p = new Parameter();
                if (Checking.CheckNameFunction(txtNamePara.Text))
                {
                    p.Name = txtNamePara.Text;
                    //xac dinh loai;
                    p.Set = comboType.Text;
                    if (radioArray.Checked)
                    {
                        p.IsArr = true;
                    }
                    if (radioSet.Checked)
                    {
                        p.IsSet = true;
                    }
                    
                    p.SystemType = Mapping.MappingSetToSystemType(p.Set);
                    p.Type = Mapping.MappingSetToType(p.Set);

                    //kiem tra tham so nhap vao co ten co trung voi nhung ten cu hay ko
                    if (Checking.CheckSameParameter(this.m_parent.ListPara.ToArray()) == -1)
                    {
                        this.m_parent.ListPara.Add(p);
                        this.m_parent.UpdateListView(); 
                    }
                    else
                    {
                        MessageBox.Show("Da ton tai ten cua tham so nay roi");
                    }

                    txtNamePara.Text = "";
                    comboType.Text = "";
                }
                else
                {
                    MessageBox.Show("Ten tham so dat khong phu hop");
                }
            }
            else
            {
                MessageBox.Show("Nhap day du thong tin can thiet!");
            }
        }
    }
}